<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        #div1{
            width: 500px;
            height: 500px;
            background-color:pink;
        }
        #div2{
            width: 350px;
            height: 350px;
            background-color:lightblue;
        }
        #div3{
            width: 200px;
            height: 200px;
            background-color:yellow;
        }
    </style>
</head>
<body>
<div id="div1">
    <div id="div2">
        <div id="div3"></div>
    </div>
</div>
<script>
    var oDiv=document.getElementsByTagName("div");
    for(var i=0;i<oDiv.length;i++){
        oDiv[i].onclick=function(ev){
            ev=ev||event;
            alert(this.id);
            event.cancelBubble=true;
        }
    }

</script>
</body>
</html>